%%%-----------------------------------
%%% @Module  : pt_12
%%% @Author  : kxp
%%% @Created : 2016.08.15
%%% @Description: 12聊天信息
%%%-----------------------------------
-module(pt_12).

%%--------------------------------------
%% Include files
%%--------------------------------------
-include("common.hrl").
-include("proto_all.hrl").

%%--------------------------------------
%% Exported Functions
%%--------------------------------------
-compile(export_all).


%%--------------------------------------
%%Protocol: 12000 聊天信息
%%--------------------------------------
read(12000,Bin) ->
    {ClientData, _} = proto_read:unpack(c2s_game_chat, Bin),	
	{c2s_game_chat, FaceId} = ClientData,
    {ok, [FaceId]};

%%--------------------------------------
%%Protocol: 12001 发送世界信息
%%--------------------------------------
read(12001,Bin) ->
    {ClientData, _} = proto_read:unpack(c2s_chat_world, Bin),	
	{c2s_chat_world ,Content} = ClientData,
    {ok, [Content]};


%%--------------------------------------
%%Protocol: 12002 牌局聊天
%%--------------------------------------
read(12002,Bin) ->
    {ClientData, _} = proto_read:unpack(c2s_chat_table, Bin),	
	{c2s_chat_table ,Content} = ClientData,
    {ok, [Content]};

%%--------------------------------------
%%Protocol: 12003牌局私聊/表情
%%--------------------------------------
read(12003,Bin) ->
    {ClientData, _} = proto_read:unpack(c2s_chat_private, Bin),	
	{c2s_chat_private ,ToUid, Content} = ClientData,
    {ok, [ToUid, Content]};

%%--------------------------------------
%%Protocol: 12004 GM命令
%%--------------------------------------
read(12004,Bin) ->
    {ClientData, _} = proto_read:unpack(c2s_chat_gm, Bin),	
	{c2s_chat_gm ,GM} = ClientData,
    {ok, [GM]};

%%--------------------------------------
%% undefined command
%%--------------------------------------
read(_Cmd, _R) ->
	?ERROR_MSG("~s pt_11 reading cmd_[~p], Data:~p~n",[misc:time_format(game_timer:now()), _Cmd, _R]),
    {error, no_match}.

%%--------------------------------------
%%Protocol: 12000 聊天信息
%%--------------------------------------
write(12000, [Seq, RecordData]) ->
    MsgPack = proto_write:pack(s2c_game_chat, RecordData),
    ServerData = <<Seq:32, MsgPack/binary>>,
    {ok, pt:pack(12000, ServerData)};

%%--------------------------------------
%%Protocol: 12001 世界信息
%%--------------------------------------
write(12001, [Seq, RecordData]) ->
    MsgPack = proto_write:pack(s2c_chat_world, RecordData),
    ServerData = <<Seq:32, MsgPack/binary>>,
    {ok, pt:pack(12001, ServerData)};

%%--------------------------------------
%%Protocol: 12002 牌局聊天
%%--------------------------------------
write(12002, [Seq, RecordData]) ->
    MsgPack = proto_write:pack(s2c_chat_table, RecordData),
    ServerData = <<Seq:32, MsgPack/binary>>,
    {ok, pt:pack(12002, ServerData)};

%%--------------------------------------
%%Protocol: 12003牌局私聊/表情
%%--------------------------------------
write(12003, [Seq, RecordData]) ->
    MsgPack = proto_write:pack(s2c_chat_private, RecordData),
    ServerData = <<Seq:32, MsgPack/binary>>,
    {ok, pt:pack(12003, ServerData)};

%%--------------------------------------
%%Protocol: 12004 GM命令
%%--------------------------------------
write(12004, [Seq, RecordData]) ->
    MsgPack = proto_write:pack(s2c_chat_gm, RecordData),
    ServerData = <<Seq:32, MsgPack/binary>>,
    {ok, pt:pack(12004, ServerData)};

%%--------------------------------------
%%Protocol: 12005 广播世界聊天
%%--------------------------------------
write(12005, [Seq, RecordData]) ->
    MsgPack = proto_write:pack(s2c_broadcast_chat_world, RecordData),
    ServerData = <<Seq:32, MsgPack/binary>>,
    {ok, pt:pack(12005, ServerData)};

%%--------------------------------------
%% undefined command 
%%--------------------------------------
write(Cmd, _R) ->
    ?ERROR_MSG("~s pt_11 writting cmd_[~p], Data:~p~n",[misc:time_format(game_timer:now()), Cmd, _R]),
    {ok, pt:pack(0, <<>>)}.


